/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pv168.reminder.swing.workers;

import cz.muni.fi.pv168.reminder.entities.Task;
import cz.muni.fi.pv168.reminder.entities.Worker;
import cz.muni.fi.pv168.reminder.managers.AssignmentManager;
import cz.muni.fi.pv168.reminder.managers.TaskManager;
import cz.muni.fi.pv168.reminder.managers.WorkerManager;
import cz.muni.fi.pv168.reminder.managers.implementation.AssignmentManagerImpl;
import cz.muni.fi.pv168.reminder.managers.implementation.TaskManagerImpl;
import cz.muni.fi.pv168.reminder.managers.implementation.WorkerManagerImpl;
import cz.muni.fi.pv168.reminder.swing.FrameMainWindow;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SwingWorker;

/**
 *
 * @author Katarína
 */
 
 public class LoadWorkersNotInTaskSwingWorker extends SwingWorker<List<Worker>, Void> {
    
    
   Long ID;
        
        public LoadWorkersNotInTaskSwingWorker(Long taskID) {
            ID = taskID;
        }

    @Override
    protected List<Worker> doInBackground() throws Exception {
        List<Worker> workers = new ArrayList<>();
        List<Worker> workersAll = new ArrayList<>();
        AssignmentManager aManager = new AssignmentManagerImpl();
        aManager.setDataSource(FrameMainWindow.getDataSource());
        WorkerManager workerManager = new WorkerManagerImpl();
        workerManager.setDataSource(FrameMainWindow.getDataSource());
        TaskManager tManager = new TaskManagerImpl();
        tManager.setDataSource(FrameMainWindow.getDataSource());
        Task task = tManager.findTaskById(ID);
        
        workers = aManager.findWorkersOfTask(task);
        workersAll =  workerManager.findAllPersons();
        
        List<Worker> tmp = new ArrayList<>();
        
        for(Worker worker : workersAll)
        {
            if(!workers.contains(worker)) tmp.add(worker);
        }
        
            
            return tmp;
        
    }

}
